home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1996 #3 / AmigaPlus_CD-ROM-EXTRA_Nr.3.bin / aminet-spiele / role on / larn / moreobj.c < prev    next >
C/C++ Source or Header  |  1997-12-31  |  19KB  |  793 lines

  1. /* moreobj.c
  2.  
  3.    Routines in this file:
  4.  
  5.    oaltar()
  6.    othrone()
  7.    odeadthrone()
  8.    ochest()
  9.    ofountain()
  10.    fntchange()
  11.    fch()
  12.    drink_fountain()
  13.    wash_fountain()
  14.    enter()
  15.    remove_gems()
  16.    sit_on_throne()
  17.    up_stairs()
  18.    down_stairs()
  19.    open_something()
  20.    close_something()
  21.    desecrate_altar()
  22.    pray_at_altar()
  23. */
  24. #include "header.h"
  25. #include "larndefs.h"
  26. #include "monsters.h"
  27. #include "objects.h"
  28. #include "player.h"
  29.  
  30.        void specify_object();
  31. static void specify_obj_nocurs();
  32. static void specify_obj_cursor();
  33. extern int dropflag ;
  34. static void move_cursor();
  35.  
  36. /*
  37.     subroutine to process an altar object
  38. */
  39. oaltar()
  40.     {
  41.     unsigned long k;
  42.  
  43.     lprcat("\nDo you (p) pray  (d) desecrate"); iopts();
  44.     while (1) switch(ttgetch())
  45.         {
  46.         case 'p':
  47.         lprcat(" pray\nDo you (m) give money or (j) just pray? ");
  48.             while (1) switch(ttgetch())
  49.                 {
  50.                 case 'j': 
  51.             lprcat("\n");
  52.             act_just_pray();
  53.             return;
  54.  
  55.                 case 'm':
  56.             act_donation_pray();
  57.             return;
  58.  
  59.                 case '\33':
  60.             return;
  61.                 };
  62.  
  63.         case 'd':
  64.         lprcat(" desecrate");
  65.         act_desecrate_altar();
  66.         return;
  67.  
  68.         case 'i':
  69.         case '\33':
  70.         ignore();
  71.         act_ignore_altar();
  72.             return;
  73.         };
  74.     }
  75.  
  76. /*
  77.     subroutine to process a throne object
  78. */
  79. othrone(arg)
  80.     int arg;
  81.     {
  82.  
  83.     lprcat("\nDo you (p) pry off jewels, (s) sit down"); iopts();
  84.     while (1)
  85.       {
  86.       while (1) switch(ttgetch())
  87.         {
  88.         case 'p':   
  89.             lprcat(" pry off");  
  90.             act_remove_gems( arg );
  91.             return;
  92.  
  93.         case 's':
  94.             lprcat(" sit down");
  95.             act_sit_throne( arg );
  96.             return;
  97.  
  98.         case 'i':
  99.         case '\33': ignore(); return;
  100.         };
  101.       }
  102.     }
  103.  
  104. odeadthrone()
  105.     {
  106.     lprcat("\nDo you (s) sit down"); iopts();
  107.     while (1)
  108.       {
  109.       while (1) switch(ttgetch())
  110.         {
  111.         case 's':   
  112.             lprcat(" sit down");  
  113.             act_sit_throne(1);
  114.             return;
  115.  
  116.         case 'i':
  117.         case '\33': ignore(); return;
  118.         };
  119.       }
  120.     }
  121.  
  122. /*
  123.     subroutine to process a chest object
  124. */
  125. ochest()
  126.     {
  127.     lprcat("\nDo you (t) take it, (o) try to open it"); iopts();
  128.     while (1)
  129.       {
  130.       switch(ttgetch())
  131.         {
  132.     case 'o':
  133.         lprcat(" open it");
  134.         act_open_chest( playerx, playery );
  135.         return;
  136.  
  137.     case 't':
  138.         lprcat(" take");
  139.         if (take(OCHEST,iarg[playerx][playery])==0)
  140.         item[playerx][playery]=know[playerx][playery]=0;
  141.         return;
  142.  
  143.         case 'i':
  144.         case '\33': ignore(); return;
  145.         };
  146.       }
  147.     }
  148.  
  149. /*
  150.     process a fountain object
  151. */
  152. ofountain()
  153.     {
  154.     cursors();
  155.     lprcat("\nDo you (d) drink, (w) wash yourself"); iopts();
  156.     while (1) switch(ttgetch())
  157.         {
  158.         case 'd':
  159.             act_drink_fountain();
  160.             return;
  161.  
  162.         case '\33':
  163.         case 'i':   
  164.             ignore();  
  165.             return;
  166.  
  167.         case 'w':   
  168.             act_wash_fountain();
  169.             return;
  170.         }
  171.     }
  172.  
  173. /*
  174.     a subroutine to raise or lower character levels
  175.     if x > 0 they are raised   if x < 0 they are lowered
  176. */
  177. fntchange(how)
  178.     int how;
  179.     {
  180.     register long j;
  181.     lprc('\n');
  182.     switch(rnd(9))
  183.         {
  184.         case 1: 
  185.             lprcat("Your strength");        
  186.             fch(how,&c[STRENGTH]);     break;
  187.         case 2:
  188.             lprcat("Your intelligence");    
  189.             fch(how,&c[INTELLIGENCE]);     break;
  190.         case 3:
  191.             lprcat("Your wisdom");          
  192.             fch(how,&c[WISDOM]);     break;
  193.         case 4: 
  194.             lprcat("Your constitution");    
  195.             fch(how,&c[CONSTITUTION]);     break;
  196.         case 5:
  197.             lprcat("Your dexterity");
  198.             fch(how,&c[DEXTERITY]);     break;
  199.         case 6:
  200.             lprcat("Your charm");
  201.             fch(how,&c[CHARISMA]);     break;
  202.         case 7: 
  203.             j=rnd(level+1);
  204.             if (how < 0)
  205.                 {
  206.                 lprintf("You lose %d hit point",(long)j);
  207.                 if (j>1) lprcat("s!"); else lprc('!');
  208.                 losemhp((int)j);
  209.                 }
  210.             else
  211.                 { lprintf("You gain %d hit point",(long)j);  if (j>1) lprcat("s!"); else lprc('!'); raisemhp((int)j); }
  212.             bottomline();       break;
  213.  
  214.         case 8: j=rnd(level+1);
  215.                 if (how > 0)
  216.                     {
  217.                     lprintf("You just gained %d spell",(long)j);  raisemspells((int)j);
  218.                     if (j>1) lprcat("s!"); else lprc('!');
  219.                     }
  220.                 else
  221.                     {
  222.                     lprintf("You just lost %d spell",(long)j);  losemspells((int)j);
  223.                     if (j>1) lprcat("s!"); else lprc('!');
  224.                     }
  225.                 bottomline();       break;
  226.  
  227.         case 9: j = 5*rnd((level+1)*(level+1));
  228.                 if (how < 0)
  229.                     {
  230.                     lprintf("You just lost %d experience point",(long)j);
  231.                     if (j>1) lprcat("s!"); else lprc('!'); loseexperience((long)j);
  232.                     }
  233.                 else
  234.                     {
  235.                     lprintf("You just gained %d experience point",(long)j);
  236.                     if (j>1) lprcat("s!"); else lprc('!'); raiseexperience((long)j);
  237.                     }
  238.                 break;
  239.         }
  240.     cursors();
  241.     }
  242.  
  243. /*
  244.     subroutine to process an up/down of a character attribute for ofountain
  245. */
  246. static fch(how,x)
  247.     int how;
  248.     long *x;
  249.     {
  250.     if (how < 0)     { lprcat(" went down by one!");    --(*x); }
  251.         else         { lprcat(" went up by one!");  (*x)++; }
  252.     bottomline();
  253.     }
  254.  
  255. /*
  256.     For command mode.  Perform drinking at a fountain.
  257. */
  258. drink_fountain()
  259.     {
  260.     cursors() ;
  261.     if (item[playerx][playery] == ODEADFOUNTAIN)
  262.         lprcat("\nThere is no water to drink!") ;
  263.  
  264.     else if (item[playerx][playery] != OFOUNTAIN)
  265.         lprcat("\nI see no fountain to drink from here!") ;
  266.  
  267.     else 
  268.         act_drink_fountain();
  269.     return;
  270.     }
  271.  
  272. /*
  273.     For command mode.  Perform washing (tidying up) at a fountain.
  274. */
  275. wash_fountain()
  276.     {
  277.     cursors() ;
  278.     if (item[playerx][playery] == ODEADFOUNTAIN)
  279.         lprcat("\nThere is no water to wash in!") ;
  280.  
  281.     else if (item[playerx][playery] != OFOUNTAIN)
  282.         lprcat("\nI see no fountain to wash at here!") ;
  283.  
  284.     else
  285.         act_wash_fountain();
  286.     return;
  287.     }
  288.  
  289. /*
  290.     For command mode.  Perform entering a building.
  291. */
  292. enter()
  293.     {
  294.     cursors() ;
  295.     switch ( item[playerx][playery] )
  296.         {
  297.         case OSCHOOL:
  298.             oschool();
  299.             break ;
  300.  
  301.         case OBANK:
  302.             obank() ;
  303.             break ;
  304.  
  305.         case OBANK2:
  306.             obank2() ;
  307.             break ;
  308.  
  309.         case ODNDSTORE:
  310.             dndstore() ;
  311.             break ;
  312.  
  313.         case OENTRANCE:
  314.             /* place player in front of entrance on level 1.  newcavelevel()
  315.                prevents player from landing on a monster/object.
  316.             */
  317.             playerx = 33 ;
  318.             playery = MAXY - 2 ;
  319.             newcavelevel( 1 );
  320.             know[33][MAXY - 1] = KNOWALL ;
  321.             mitem[33][MAXY - 1] = 0 ;
  322.             draws( 0, MAXX, 0, MAXY );
  323.             showcell(playerx, playery);         /* to show around player */
  324.             bot_linex() ;
  325.             break ;
  326.  
  327.         case OTRADEPOST:
  328.             otradepost();
  329.             break;
  330.  
  331.         case OLRS:
  332.             olrs();
  333.             break;
  334.  
  335.         case OHOME:
  336.             ohome();
  337.             break;
  338.  
  339.         default :
  340.             lprcat("\nThere is no place to enter here!\n");
  341.             break;
  342.         }
  343.     }
  344.  
  345. /*
  346.     For command mode.  Perform removal of gems from a jeweled throne.
  347. */
  348. remove_gems ( )
  349.     {
  350.     cursors();
  351.     if (item[playerx][playery] == ODEADTHRONE)
  352.         lprcat("\nThere are no gems to remove!");
  353.     
  354.     else if (item[playerx][playery] == OTHRONE)
  355.         act_remove_gems(0);
  356.  
  357.     else if (item[playerx][playery] == OTHRONE2)
  358.         act_remove_gems(1);
  359.  
  360.     else
  361.         lprcat("\nI see no throne here to remove gems from!");
  362.     return;
  363.     }
  364.  
  365. /*
  366.     For command mode.  Perform sitting on a throne.
  367. */
  368. sit_on_throne( )
  369.     {
  370.     cursors();
  371.     if (item[playerx][playery] == OTHRONE)
  372.         act_sit_throne(0);
  373.     
  374.     else if ((item[playerx][playery] == OTHRONE2) ||
  375.              (item[playerx][playery] == ODEADTHRONE))
  376.         act_sit_throne(1);
  377.     
  378.     else
  379.         lprcat("\nI see no throne to sit on here!");
  380.  
  381.     return;
  382.     }
  383.  
  384. /*
  385.     For command mode.  Checks that player is actually standing at a set up
  386.     up stairs or volcanic shaft.  
  387. */
  388. up_stairs()
  389.     {
  390.     cursors();
  391.     if (item[playerx][playery] == OSTAIRSDOWN)
  392.         lprcat("\nThe stairs don't go up!");
  393.  
  394.     else if (item[playerx][playery] == OVOLUP)
  395.         act_up_shaft();
  396.  
  397.     else if (item[playerx][playery] != OSTAIRSUP)
  398.         lprcat("\nI see no way to go up here!");
  399.  
  400.     else
  401.         act_up_stairs();
  402.     }
  403.  
  404. /*
  405.     For command mode.  Checks that player is actually standing at a set of
  406.     down stairs or volcanic shaft.
  407. */
  408. down_stairs()
  409.     {
  410.     cursors();
  411.     if (item[playerx][playery] == OSTAIRSUP)
  412.         lprcat("\nThe stairs don't go down!");
  413.  
  414.     else if (item[playerx][playery] == OVOLDOWN)
  415.         act_down_shaft();
  416.  
  417.     else if (item[playerx][playery] != OSTAIRSDOWN)
  418.         lprcat("\nI see no way to go down here!");
  419.  
  420.     else
  421.         act_down_stairs();
  422.     }
  423.  
  424. /*
  425.     For command mode.  Perform opening an object (door, chest).
  426. */
  427. open_something( )
  428.     {
  429.     int x,y;    /* direction to open */
  430.     char tempc; /* result of prompting to open a chest */
  431.  
  432.     cursors();
  433.     /* check for confusion.
  434.     */
  435.     if (c[CONFUSE])
  436.         {
  437.         lprcat("You're too confused!");
  438.         beep();
  439.         return;
  440.         }
  441.  
  442.     /* check for player standing on a chest.  If he is, prompt for and
  443.        let him open it.  If player ESCs from prompt, quit the Open
  444.        command.
  445.     */
  446.     if (item[playerx][playery] == OCHEST)
  447.         {
  448.         lprcat("There is a chest here.  Open it?");
  449.         if ((tempc = getyn()) == 'y')
  450.             {
  451.             act_open_chest( playerx, playery );
  452.             dropflag = 1;     /* prevent player from picking back up if fail */
  453.             return;
  454.             }
  455.         else if (tempc != 'n' )
  456.             return;
  457.         }
  458.  
  459.     /* get direction of object to open.  test 'openability' of object
  460.        indicated, call common command/prompt mode routines to actually open.
  461.     */
  462.     dirsub( &x, &y );
  463.     switch( item[x][y] )
  464.         {
  465.         case OOPENDOOR:
  466.             lprcat("The door is already open!");
  467.             beep();
  468.             break;
  469.  
  470.         case OCHEST:
  471.             act_open_chest( x, y );
  472.             break;
  473.  
  474.         case OCLOSEDDOOR:
  475.             act_open_door( x, y );
  476.             break;
  477.  
  478.         default:
  479.             lprcat("You can't open that!");
  480.             beep();
  481.             break;
  482.         }
  483.     }
  484.  
  485. /*
  486.     For command mode.  Perform the action of closing something (door).
  487. */
  488. close_something()
  489.     {
  490.     int x,y;
  491.  
  492.     cursors();
  493.     /* check for confusion.
  494.     */
  495.     if (c[CONFUSE])
  496.         {
  497.         lprcat("You're too confused!");
  498.         beep();
  499.         return;
  500.         }
  501.  
  502.     /* get direction of object to close.  test 'closeability' of object
  503.        indicated.
  504.     */
  505.     dirsub( &x, &y );
  506.     switch( item[x][y] )
  507.         {
  508.         case OCLOSEDDOOR:
  509.             lprcat("The door is already closed!");
  510.             beep();
  511.             break;
  512.  
  513.         case OOPENDOOR:
  514.             if (mitem[x][y])
  515.                 {
  516.                 lprcat("Theres a monster in the way!");
  517.                 return;
  518.                 }
  519.             item[x][y] = OCLOSEDDOOR;
  520.             know[x][y] = 0 ;
  521.             iarg[x][y] = 0 ;
  522.             break;
  523.  
  524.         default:
  525.             lprcat("You can't close that!");
  526.             beep();
  527.             break;
  528.         }
  529.     }
  530.  
  531. /*
  532.     For command mode.  Perform the act of descecrating an altar.
  533. */
  534. desecrate_altar()
  535.     {
  536.     cursors();
  537.     if (item[playerx][playery] == OALTAR)
  538.         act_desecrate_altar();
  539.     else
  540.         lprcat("\nI see no altar to desecrate here!");
  541.     }
  542.  
  543. /*
  544.     For command mode.  Perform the act of praying at an altar.
  545. */
  546. pray_at_altar()
  547.     {
  548.     extern char prayed ;
  549.  
  550.     cursors();
  551.     if (item[playerx][playery] != OALTAR)
  552.         lprcat("\nI see no altar to pray at here!");
  553.     else
  554.     act_donation_pray();
  555.     prayed = 1 ;
  556.     }
  557.  
  558. /*
  559.     Identify objects for the player.
  560. */
  561. void specify_object()
  562.     {
  563.     cursors();
  564.     lprcat("\n\nIdentify unknown object by cursor [ynq]?");
  565.     while (1)
  566.         {
  567.         switch (ttgetch())
  568.             {
  569.             case '\33':
  570.             case 'q':
  571.                 return;
  572.                 break;
  573.             case 'y':
  574.             case 'Y':
  575.                 specify_obj_cursor();
  576.                 return;
  577.                 break;
  578.             case 'n':
  579.             case 'N':
  580.                 specify_obj_nocurs();
  581.                 return;
  582.                 break;
  583.             default:
  584.                 break;
  585.             }
  586.         }
  587.     }
  588.  
  589. /* perform the actions of identifying the object/monster associated with a
  590.    character typed by the user.  assumes cursors().
  591. */
  592. static void specify_obj_nocurs()
  593.     {
  594.     register int i, j, flag;
  595.  
  596.     lprcat("\nType object character:");
  597.     switch (i=ttgetch())
  598.         {
  599.         case '\33':
  600.         case '\n':
  601.             return;
  602.         case '@':
  603.             lprintf("\n@: %s", logname );
  604.             return;
  605.         case ' ':
  606.             lprintf("\n : An as-yet-unseen place in the dungeon" );
  607.             return;
  608.         default:
  609.             if ( i == floorc )
  610.                 {
  611.                 lprc('\n');
  612.                 lprc(floorc);
  613.                 lprintf(": the floor of the dungeon");
  614.                 return;
  615.                 }
  616.             flag = FALSE;
  617.             for (j=0; j < MAXMONST+8 ; j++)
  618.                 if (i==monstnamelist[j])
  619.                     {
  620.                     lprintf("\n%c: %s", i, monster[j].name);
  621.                     flag = TRUE;
  622.                     }
  623.             /* check for spurious object character
  624.             */
  625.             if (i != '_')
  626.                 for (j=0; j < MAXOBJECT; j++)
  627.                     if (i==objnamelist[j])
  628.                         {
  629.                         lprc('\n');
  630.                         if (boldobjects)
  631.                             {
  632.                             setbold();
  633.                             lprc(i);
  634.                             resetbold();
  635.                             }
  636.                         else
  637.                             lprc(i);
  638.                         lprintf(": %s", objectname[j]);
  639.                         flag = TRUE;
  640.                         }
  641.             if (!flag)
  642.                 lprintf("\n%c: unknown monster/object", i );
  643.             return;
  644.             break;
  645.         }
  646.     }
  647.  
  648. static void specify_obj_cursor()
  649.     {
  650. #if __STDC__
  651.     signed char objx, objy;
  652. #else
  653.     char objx, objy;
  654. #endif
  655.     int i;
  656.  
  657.     lprcat("\nMove the cursor to an unknown item.");
  658.     lprcat("\n(For instructions type a ?)");
  659.  
  660.     objx = playerx ;
  661.     objy = playery ;
  662.     cursor( objx+1, objy+1 );
  663. /* make cursor visible.
  664. */
  665.     while (1)
  666.         {
  667.         switch(ttgetch())
  668.             {
  669.             case '?':
  670.                 cursors();
  671.                 lprcat("\nUse [hjklnbyu] to move the cursor to the unknown object.");
  672.                 lprcat("\nType a . when the cursor is at the desired place.");
  673.                 lprcat("\nType q, Return, or Escape to exit.");
  674.                 cursor( objx+1, objy+1);
  675.                 break;
  676.  
  677.             case '\33':
  678.             case 'q':
  679.             case '\n':
  680. /* reset cursor
  681. */
  682.                 cursor( playerx+1, playery+1);
  683.                 return;
  684.             case '.':
  685. /* reset cursor
  686. */
  687.                 cursor( playerx+1, playery+1);
  688.                 cursors();
  689.  
  690.                 if ((objx == playerx) &&
  691.                     (objy == playery))
  692.                     {
  693.                     lprintf("\n@: %s", logname );
  694.                     return;
  695.                     }
  696.  
  697.                 i = mitem[objx][objy];
  698.                 if ( i && ( know[objx][objy] & KNOWHERE))
  699.  
  700.                     /* check for invisible monsters and not display
  701.                     */
  702.                     if ( monstnamelist[i] != floorc )
  703.                         {
  704.                         lprintf("\n%c: %s", monstnamelist[i], monster[i].name);
  705.                         return;
  706.                         }
  707.  
  708.                 /* handle floor separately so as not to display traps, etc.
  709.                 */
  710.                 i = item[objx][objy];
  711.                 if ( i == 0 )
  712.                     {
  713.                     lprc('\n');
  714.                     lprc(floorc);
  715.                     lprintf(": the floor of the dungeon");
  716.                     return;
  717.                     }
  718.  
  719.                 if ( know[objx][objy] & HAVESEEN )
  720.                     {
  721.                     lprc('\n');
  722.                     if (boldobjects)
  723.                         {
  724.                         setbold();
  725.                         lprc(objnamelist[i]);
  726.                         resetbold();
  727.                         }
  728.                     else
  729.                         lprc(objnamelist[i]);
  730.                     lprintf(": %s", objectname[i]);
  731.                     return;
  732.                     }
  733.  
  734.                 lprintf("\n : An as-yet-unseen place in the dungeon" );
  735.                 return;
  736.  
  737.             case 'H':
  738.             case 'h':
  739.                 move_cursor( &objx, &objy, 4);
  740.                 break;
  741.             case 'J':
  742.             case 'j':
  743.                 move_cursor( &objx, &objy, 1);
  744.                 break;
  745.             case 'K':
  746.             case 'k':
  747.                 move_cursor( &objx, &objy, 3);
  748.                 break;
  749.             case 'L':
  750.             case 'l':
  751.                 move_cursor( &objx, &objy, 2);
  752.                 break;
  753.             case 'B':
  754.             case 'b':
  755.                 move_cursor( &objx, &objy, 8);
  756.                 break;
  757.             case 'N':
  758.             case 'n':
  759.                 move_cursor( &objx, &objy, 7);
  760.                 break;
  761.             case 'Y':
  762.             case 'y':
  763.                 move_cursor( &objx, &objy, 6);
  764.                 break;
  765.             case 'U':
  766.             case 'u':
  767.                 move_cursor( &objx, &objy, 5);
  768.                 break;
  769.             default:
  770.                 break;
  771.             }
  772.         }
  773.     }
  774.  
  775. static void move_cursor( xx, yy, cdir )
  776. #if __STDC__
  777. signed char *xx ;
  778. signed char *yy ;
  779. #else
  780. char *xx ;
  781. char *yy ;
  782. #endif
  783. unsigned char cdir ;
  784.     {
  785.     *xx += diroffx[cdir];
  786.     *yy += diroffy[cdir];
  787.     if ( *yy < 0 ) *yy = MAXY-1;
  788.     if ( *yy > MAXY-1 ) *yy = 0;
  789.     if ( *xx < 0 ) *xx = MAXX-1;
  790.     if ( *xx > MAXX-1 ) *xx = 0;
  791.     cursor( *xx+1, *yy+1 );
  792.     }
  793.